package cn.stylefeng.guns.modular.erlist.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.stylefeng.guns.modular.erlist.service.ErListService;
import cn.stylefeng.guns.modular.erlist.model.param.ErListParam;

import javax.annotation.Resource;

/**
 * er_list 控制器
 *
 * @author: w
 * @date: 2021/06/12 15:52
 */
@RestController
public class ErListController {

    @Resource
    private ErListService erListService;

    /**
     * 条件查询er_list  根据作者 标题 模糊查询
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @GetMapping("/erList/page")
    @BusinessLog(title = "er_list_条件查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(ErListParam erListParam) {
        return new SuccessResponseData(erListService.page(erListParam));
    }

    /**
     * 根据分类查询
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @GetMapping("/erList/class")
    @BusinessLog(title = "er_list_分类查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getListByClassify(ErListParam erListParam) {
        return new SuccessResponseData(erListService.getListByClassify(erListParam));
    }


    /**
     * 获取全部er_list
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @GetMapping("/erList/list")
    @BusinessLog(title = "er_list_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(ErListParam erListParam) {
        return new SuccessResponseData(erListService.list(erListParam));
    }

    /**
     * 查看详情er_list
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @GetMapping("/erList/detail")
    @BusinessLog(title = "er_list_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(ErListParam.detail.class) ErListParam erListParam) {
        return new SuccessResponseData(erListService.detail(erListParam));
    }

    /**
     * 添加er_list
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @PostMapping("/erList/add")
    @BusinessLog(title = "er_list_增加")
    public ResponseData add(@RequestBody ErListParam erListParam) {
        return new SuccessResponseData( erListService.add(erListParam));
    }

    /**
     * 删除er_list
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @PostMapping("/erList/delete")
    @BusinessLog(title = "er_list_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(ErListParam.delete.class) ErListParam erListParam) {
        erListService.delete(erListParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑er_list
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @PostMapping("/erList/edit")
    @BusinessLog(title = "er_list_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(ErListParam.edit.class) ErListParam erListParam) {
        erListService.edit(erListParam);
        return new SuccessResponseData();
    }
    /**
     * 获赞总数
     *
     * @author w
     * @date 2021/06/12 15:52
     */
    @PostMapping("/erList/alllike")
    @BusinessLog(title = "获赞数")
    public ResponseData allLike(@RequestBody ErListParam erListParam) {
        return new SuccessResponseData(erListService.getAllLike(erListParam));
    }

    @PostMapping("/erList/myarticle")
    @BusinessLog(title = "我的发布")
    public ResponseData getMyArticle(@RequestBody ErListParam erListParam) {
        return new SuccessResponseData(erListService.getMyArticle(erListParam));
    }
}
